package org.yagnus.stats.summary.univariate;

import java.util.Set;

import org.yagnus.langutils.BasicAccessibleMap;
import org.yagnus.langutils.mutables.MutableLong;

/**
 * This class counts stuff and returns the histogram;
 * 
 * @author u
 * 
 */
public class LongHistogram<O> {
    BasicAccessibleMap<O, MutableLong> bam = new BasicAccessibleMap<O, MutableLong>(new MutableLong(0)) {
        public MutableLong allocate() {
            return new MutableLong(0);
        }
    };

    public long add(O s) {
        return bam.getAllocate(s).inc();
    }

    public long add(O s, long v) {
        return bam.getAllocate(s).inc(v);
    }

    public long get(O s) {
        return bam.getWithDefault(s).get();
    }

    public Set<O> getAllValues() {
        return bam.keySet();
    }
    public int size(){
        return bam.size();
    }
}
